package com.joinway.framework.admin.core.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class TableHelper {

	private final static Logger log = LoggerFactory.getLogger(TableHelper.class);
	
//	public static List<? extends DomainEntity> convert(String table, List<Map<String, ?>> records) throws Exception {
//		Class<? extends DomainEntity> domainClass = BeanTypeFactory.getDomainClass(table);
//
//		return convert(records, domainClass);
//	}
//
//	public static DomainEntity convert(String table, Map<String, ?> record) throws Exception {
//		Class<? extends DomainEntity> domainClass = BeanTypeFactory.getDomainClass(table);
//
//		return convert(record, domainClass);
//	}

	public static <T> List<T> convert(List<Map<String, ?>> records, Class<T> domainClass) throws Exception {
		List<T> domains = new ArrayList<>();
		for (Map<String, ?> map : records) {
			T domain = null;//DomainConverter.create(map, domainClass).convert();
			domains.add(domain);
		}

		return domains;
	}

//	public static <T extends DomainEntity> T convert(Map<String, ?> record, Class<T> domainClass) throws Exception {
//		List<Map<String, ?>> list = new ArrayList<>();
//		if(record != null && record.size() > 0){
//			list.add(record);
//		}
//		
//		List<T> domains = convert(list, domainClass);
//		
//		return CollectionUtils.isEmpty(domains) ? null : domains.get(0);
//	}
//
	public static Integer getFromPageIndex(Integer page, Integer rows){
		Integer index = null;

		if (page != null && rows != null) {
			index = (page - 1) * rows;
		}

		return index;
	}

	private TableHelper() {}
}
